import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-02
 * Time: 18:04
 */

public class Exercises {
    public static void main(String[] args) {
        //1.创建三个Dog {name,age} 放入到ArrayList中 赋给List引用
        //2.用迭代器和增强for循环的方法来遍历
        //3.重写Dog 和 toString方法 输出name和age

        ArrayList<Dog> list = new ArrayList<>();

        Dog dog1 = new Dog("可乐",19);
        Dog dog2 = new Dog("雪碧",20);
        Dog dog3 = new Dog("芬达",21);

        list.add(dog1);
        list.add(dog2);
        list.add(dog3);
        for (Object o : list) {
            System.out.println(o);
        }

        System.out.println("------------------");

        //不是创建对象 是调用接口
        Iterator<Dog> iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }

    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name,int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return this.name + this.age;
    }
}